/*	
	This program is free software; you can redistribute it and/or modify 
	it under the terms of the GNU General Public License as published by 
	the Free Software Foundation; either version 2 of the License, or 
	any later version.

    	This program is distributed in the hope that it will be useful, but 
	WITHOUT ANY WARRANTY; without even the implied warranty of 
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
	General Public License for more details.

    	You should have received a copy of the GNU General Public License 
	along with this program; if not, write to the Free Software 
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
	USA
*/

#include<stdio.h>
#include<driver.h>
#include<string.h>

// funzione per stampare a video una stringa
void printk(char *stringa) {
	int i=0;
	while(stringa[i]) {
		switch(stringa[i]) {
			case '\n':
				newk(); i++; break;
			default:
				putk(stringa[i],0x7); i++; break;
		}
	}
}

int conta_bit(int num) {
	int tot,div=1,i=0;
	while(1) {
		tot=num/div;
		div=div*10;
		if(tot==0) {break;}
		i++;
	}
	return i;
}

void printn(unsigned long int num) {
	if(num==0) putk(0x30,0x7);
	int i,div=1,resto,tot;
	int conta=conta_bit(num);
	for(i=0;i<(conta-1);i++) div=div*10;
	for(i=0;i<conta;i++){
		tot=num/div;
		resto=num%div;
		num=resto;
		div=div/10;
		putk(tot+0x30,0x7);
	}
}

void putk(char carattere,char attributo) {
	add_char(riga,colonna,carattere,attributo);
	trasloca();
	colonna++;
	if(colonna>=80) {newk();}
}

void printok() {
	colonna=76;
	putk('[',0x7); putk('o',0x2); putk('k',0x2); putk(']',0x7);
}

// funzione per andare a capo
void newk() {if(riga>=23) {scroll(); colonna=0;} else {riga++; colonna=0;}}

void debug(char *stringa) {
	char *debug_string;
	strcopy(debug_string,"DEBUG: ");
	int i=0;
	while(debug_string[i]) {
		putk(debug_string[i],0xA); i++;
	}
	i=0;
	while(stringa[i]) {
		putk(stringa[i],0xA); i++;
	}
}
